#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"

#include "ViewEventFilter.h"
#include "EditorProxy.h"
#include "FileSystemModel.h"
#include "RecentModel.h"
#include "Settings.h"

#include <QDeclarativeContext>

Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QScopedPointer<QApplication> app(createApplication(argc, argv));
    QmlApplicationViewer viewer;
    QDeclarativeContext *ctxt = viewer.rootContext();

    qmlRegisterType<EditorProxy>("TextEditor", 1, 0, "TextEditorItem");
    qmlRegisterType<FileSystemModel>("FileSystemModel", 1, 0, "FileSystemModelItem");
    qmlRegisterType<RecentModel>("RecentModel", 1, 0, "RecentModelItem");

    ViewEventFilter eventFilter;
    viewer.installEventFilter(&eventFilter);

    ctxt->setContextProperty("Settings", Settings::instance());

    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer.setMainQmlFile(QLatin1String("qml/MeeTxtEdit/main.qml"));
    viewer.showExpanded();

    int result = app->exec();

    // Call that explicit since the dtor of Settings may not be called...
    Settings::instance()->saveChanges();

    return result;
}
